#ifndef MAINUI_H
#define MAINUI_H

#include "app_common.h"
#include "ui_MainUI.h"

QT_CHARTS_USE_NAMESPACE

namespace Ui {
class MainUI;
}

class MainUI : public QWidget
{
    Q_OBJECT
    
public:
    explicit MainUI(QWidget *parent = nullptr);
    ~MainUI();
private slots:
    void on_btnZoomIn_clicked();
    void on_btnZoomOut_clicked();
    void on_btnUp_clicked();
    void on_btnDown_clicked(); 
    void on_btnLeft_clicked();
    void on_btnRight_clicked();
    void on_btnSlip_clicked();
    void on_btnScreenshot_clicked();
    void on_btnCSV_clicked();
    void on_btnGit_clicked();
    void on_btnRefreshSerial_clicked();
    void on_btnSerialOpenClose_clicked();
private slots:
    void on_serialReadyRead();
private:
    void m_initUI();
    void m_intiChart();
    void m_initLblVerse();
    void m_initLcd();
private:
    void m_refreshSerialList();
    bool m_comGetChar(char *ch, uint32_t port = 0);
    void m_comAnalysis();
    void m_comExexCmd();
    void m_crcChkErrDis();
    void m_ptChkPassDis();
    void m_mainSubSecDis(int main_sec, int sun_sec);
private:
    void m_initData();
    void m_addSeries();
    void m_connectMarkers();
    void m_handleMarkerClicked();
    void m_slipAPt();
    void m_movieAtStartup();
    QFont m_globalTootipCfg(QString fontName , int fontSize);
    void m_chartScreenshot();
private:
    void m_initTimer();
    void m_handleTimeout_10ms();
    void m_handleTimeout_100ms();
    void m_handleTimeout_1000ms();
private:
    Ui::MainUI *ui;
    
    /* 波形*/
    QChart *m_chart;
    QChartView *m_chartView;
    QGridLayout *m_mainLayout;
    QValueAxis *m_axisX;
    QValueAxis *m_axisY;
    QList<QSplineSeries *> m_series;
    bool m_isOpenSlip;
    
    /* 串口*/
    QSerialPort m_serial;
    QByteArray m_SerialRevBuf;
    int m_crcErrCnt;
    int m_crcPassCnt;
    int m_revPtCnt;
    
    /*串口解析BUF & 接收索引*/
    static uint8_t analysisBuf[MAX_ANALYSIS_LEN];    /*用于解析帧数据*/
    static uint16_t analysisIndex;
    
    /* 定时器*/
    QTimer m_timer10ms;
    QTimer m_timer100ms;
    QTimer m_timer1000ms;
};


#endif // MAINUI_H
